package com.jsp.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jsp.bean.UserBean;
import com.jsp.dao.FindUserDao;


public class FindUserServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
    public FindUserServlet(){
	super();
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int currPage=1;
		if(request.getParameter("page")!=null){
			currPage=Integer.parseInt(request.getParameter("page"));
		}
		FindUserDao dao=new FindUserDao();
		List<UserBean> list=dao.find(currPage);
		request.setAttribute("list", list);
		int pages;
		int count=dao.findCount();
		if (count%UserBean.Pagesize==0){
			pages=count/UserBean.Pagesize;
		}else{
			pages=count/UserBean.Pagesize+1;
		}
			StringBuffer sb=new StringBuffer();
			for(int i=1;i<=pages;i++){
				if(i==currPage){
					sb.append("["+i+"]");
				}else{
					sb.append("<a href='FindUserServlet?page="+i+"'>"+i+"</a>");
			}
			sb.append("");	
		}
			request.setAttribute("bar", sb.toString());
			request.getRequestDispatcher("/admin/pro.jsp").forward(request, response);
	}



}
